//:C10:Initializer.h
//Static initialization technique
#ifndef INITIALIZER_H_
#define INITIALIZER_H_
#include <iostream>
extern int x;    // Declaration, not definitions
extern int y;

class Initializer
{
    static int initCount;
    public:
        Initializer()
        {
            std::cout << "Initializer()" << std::endl;
            // Initialize first time only
            if(initCount++ == 0)
            {
                std::cout << "performing initialization"
                          << std::endl;
                x = 100;
                y = 200;          
            }
        }
        ~Initializer()
        {
            std::cout << "~Initializer() " << std::endl;
            // Clean up last time only
            if(--initCount == 0)
            {
                std::cout << "performing cleanup"
                          << std::endl;
                // Any necessary cleanup here          
            }
        }
};

// The following creates one object in each
// file where Initializer.h is included, but that
// object is only visible within that file:
static Initializer init;

#endif